package com.company.gas.controller;

import com.company.gas.pojo.SystemUser;
import com.company.gas.service.ISystemUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "用户管理相关接口")
@RequestMapping("/gas/systemUser")
public class SystemUserController {
    @Autowired
    private ISystemUserService iSystemUserService;
    //查询全部用户
    @GetMapping("/querySystemUserList")
    @ApiOperation("查询全部用户")
    public List<SystemUser> querySystemUserList(){
        List<SystemUser> systemUserList = iSystemUserService.querySystemUserList();
        for (SystemUser systemUser : systemUserList) {
            System.out.println(systemUser);
        }
        return systemUserList;
    }
    //通过ID查找单个用户
    @GetMapping("/querySystemUserByID")
    @ApiOperation("根据userID查询指定用户")
    public SystemUser querySystemUserByID(@RequestParam(value = "用户ID") String userId){
        SystemUser systemUser = iSystemUserService.querySystemUserByID(userId);
        return systemUser;
    }
    //增加用户
    @GetMapping("/addSystemUser")
    @ApiOperation("添加一个用户")
    public String addSystemUser(@RequestParam(value = "用户ID") String userId,@RequestParam(value = "用户密码") String password,
                                @RequestParam(value = "用户权限") String privilege, @RequestParam(value = "标识符") Boolean flag,
                                @RequestParam(value = "创建者")String createBy,@RequestParam(value = "修改者") String modifyBy){
        int isaddSystemUser = iSystemUserService.addSystemUser(userId, password, privilege, flag, createBy, modifyBy);
        if(isaddSystemUser == 1){
            return "add success";
        }else {
            return "failed";
        }

    }
    //删除用户
    @GetMapping("/deleteSystemUserByID")
    @ApiOperation("删除一个用户")
    public String deleteSystemUserByID(@RequestParam(value = "用户ID") String userId){
        int isdeleteSystemUserByID = iSystemUserService.deleteSystemUserByID(userId);
        if (isdeleteSystemUserByID == 1){
            return "delete success";
        }else {
            return "failed";
        }
    }
    //修改用户
    @GetMapping("/updateSystemUser")
    @ApiOperation("修改一个用户")
    public String updateSystemUser(@RequestParam(value = "用户ID") String userId,@RequestParam(value = "用户密码") String password,
                                   @RequestParam(value = "用户权限")String privilege,@RequestParam(value = "修改者") String modifyBy){
        int isupdateSystemUser = iSystemUserService.updateSystemUser(userId, password, privilege, modifyBy);
        if (isupdateSystemUser == 1){
            return "update success";
        }else {
            return "failed";
        }
    }
}
